<?php
/*
 * 文章控制器
 */
namespace Api\Controller;
use  Think\Controller;

class NewsController extends CommonController {
//	列表接口	
	public function newsList()
	{
		$conds = array(
			'status' => 1,
		);
		$page = $_REQUEST['page'] ? $_REQUEST['page'] : 1;
		$pageSize = $_REQUEST['pageSize'] ? $_REQUEST['pageSize'] : 10;
		$data = D('News')->getNewsList($conds,$page,$pageSize);
		if($data){
		    return api_success('成功！',$data);
		}
		return api_error('no data!');

	}
	
//	详情接口
	public function newsDetail()
	{
		$accept = $_REQUEST;
		$news_id = intval($accept['id']);
		if(!$news_id){
			return apiShow('文章id非法或不存在');
		}  	
		$news = D('News')->getNewsById($news_id);
		if(!$news || $news['status']!=1){
			return apiShow('文章不存在或状态异常');
		}
		$newsContent = D('NewsContent')->getContentById($news_id); 
		if($newsContent){
			$news['content'] = $newsContent['content'];
			return apiShow('success',200,$news);
		}
		return apiShow('文章详情获取失败');
	}
	
//	相关文章根据作者推荐 默认为1即admin
	public function relatedNews (){
//		$userid = I('uid');
		$userid = I('uid') ? I('uid') :1;
		
		$conds = array(
			'status' => 1,
			'user_id'=>$userid
		);
		$page = $_REQUEST['page'] ? $_REQUEST['page'] : 1;
		$pageSize = $_REQUEST['pageSize'] ? $_REQUEST['pageSize'] : 8;
		$data = D('News')->getNewsList($conds,$page,$pageSize);
		if($data){
			return apiShow('success',200,$data);
		}
		return apiShow('木有了',404);
	}
}